package com.tv.enoguia.fragment;


import java.io.File;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.Facebook;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sromku.simple.fb.Permission;
import com.sromku.simple.fb.SimpleFacebook;
import com.sromku.simple.fb.SimpleFacebookConfiguration;
import com.sromku.simple.fb.entities.Feed;
import com.sromku.simple.fb.listeners.OnLoginListener;
import com.sromku.simple.fb.listeners.OnPublishListener;
import com.tv.enoguia.R;
import com.tv.enoguia.bean.Celler;
import com.tv.enoguia.database.MySQLiteHelper;
import com.tv.enoguia.share.twiter.Twitt_Sharing;

public class DetailBussinessFragment extends Fragment implements
		OnTouchListener {

	TextView title;
	ImageButton btnBack, btnFace, btnTw;
	
	Button btnPhone, btnWeb, btnEmail;
	
	Dialog dC, dW, dM;
	
	TextView titleDirection;
	ViewGroup llDirection;
	
	ImageButton btnLike;
	
	String id;
	MySQLiteHelper db;
	
	int liked;
	
	Celler celler = new Celler();
	TextView titleCategory, txtDientich, txtSanluong, txtDes, txtAddress, txtListVins; 
	ImageView imgLogo, imgCover;
	DisplayImageOptions options = new DisplayImageOptions.Builder()
								.cacheInMemory(false).cacheOnDisc(true)
								.bitmapConfig(Config.RGB_565)
								.build();
	
	
	TextView txtSchedule, txtPrice, txtLang, txtCapicity, txtWine, txtVisit;
	
	Facebook facebook = new Facebook("798278870223318");
	AsyncFacebookRunner mAsyncRunner;
	
	// Replace your KEY here and Run ,
	public final String consumer_key = "eekLDde1YhuwnE9NPEGRoxLxj";
	public final String secret_key = "RsjJvknYZjrxXuByt9j4iscH43m70ZVlFERxj8DvBWOY0hBJzf";
	File casted_image;

	String string_img_url = null , string_msg = null;
	
	
	Permission[] permissions = new Permission[] {
		    Permission.USER_PHOTOS,
		    Permission.EMAIL,
		    Permission.PUBLISH_ACTION
		};
	
	SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder()
    .setAppId("798278870223318")
    .setNamespace("enoguia")
    .setPermissions(permissions)
    .build();
	
	SimpleFacebook mSimpleFacebook;
	
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Bundle argument = getArguments();
		if (argument != null)
		{
			id = argument.getString("id");
			
			db = new MySQLiteHelper(getActivity());
			
			liked = argument.getInt("liked");
			if (liked == 1){
				celler = db.getDetailCellerLike(id);
			} else {
				celler = db.getDetailCeller(id);	
			}
		}
		
		SimpleFacebook.setConfiguration(configuration);

	}
	
	public static DetailBussinessFragment newInstance() {
		DetailBussinessFragment f = new DetailBussinessFragment();
	    return f;
	}
	
	
	
	
	
	@Override
	public void onResume() {
		super.onResume();
		mSimpleFacebook = SimpleFacebook.getInstance(getActivity());
	}
	
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
	    mSimpleFacebook.onActivityResult(getActivity(), requestCode, resultCode, data); 
	    super.onActivityResult(requestCode, resultCode, data);
	} 


	

	ViewGroup v;
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		if(v==null) {
			v = (ViewGroup) inflater.inflate(R.layout.activity_detail_bussiness, container, false);
		} else {
			((ViewGroup) v.getParent()).removeView(v);
		}
		
		title = (TextView) v.findViewById(R.id.title);
		btnBack = (ImageButton) v.findViewById(R.id.btn_back);
		btnBack.setVisibility(View.VISIBLE);
		
		btnPhone = (Button) v.findViewById(R.id.btn_phone);
		btnWeb = (Button) v.findViewById(R.id.btn_web);
		btnEmail = (Button) v.findViewById(R.id.btn_email);
		
		titleDirection = (TextView) v.findViewById(R.id.txt_title_direction);
		titleCategory = (TextView) v.findViewById(R.id.txt_name_category);
		txtDientich = (TextView) v.findViewById(R.id.txt_dientich);
		txtSanluong = (TextView) v.findViewById(R.id.txt_sanluong);
		txtDes = (TextView) v.findViewById(R.id.txt_des);
		
		imgLogo = (ImageView) v.findViewById(R.id.img_avatar);
		imgCover = (ImageView) v.findViewById(R.id.img_bussiness);
		txtAddress = (TextView) v.findViewById(R.id.txt_address);
		txtListVins = (TextView) v.findViewById(R.id.lista_vins);
		
		llDirection = (ViewGroup) v.findViewById(R.id.ll_direction);
		
		btnLike = (ImageButton) v.findViewById(R.id.ll_favor);
		
		Log.i("DATA", "LIKE: "+liked);
		
		if (liked == 1){
			btnLike.setImageResource(R.drawable.btn_like_selector_dis);
		} else {
			btnLike.setImageResource(R.drawable.btn_like_selector);	
		}
		
		btnFace = (ImageButton) v.findViewById(R.id.btn_facebook);
		btnTw = (ImageButton) v.findViewById(R.id.btn_tw);
		
		//list options
		txtSchedule = (TextView) v.findViewById(R.id.schedules_content);
		txtPrice = (TextView) v.findViewById(R.id.price_content);
		txtLang = (TextView) v.findViewById(R.id.lang_content);
		txtCapicity = (TextView) v.findViewById(R.id.capacity_content);
		txtWine = (TextView) v.findViewById(R.id.wines_content);
		txtVisit = (TextView) v.findViewById(R.id.visit_content);
		
		//check locate
		
		Log.i("DATA", ""+Locale.getDefault().getISO3Language().toString());
		
		String language = Locale.getDefault().getISO3Language().toString(); 
		
		if (language.equals("eng")){
			init();
		} else if (language.equals("cat")) {
			initCA();
		}else if (language.equals("spa")) {
			initES();
		} else if (language.equals("vie")) {
			init();
		}
		
		
		
		return v;
	}




	void init() {
		
		if (celler.getCellarName().length() > 30){
			title.setText(celler.getCellarName().substring(0, 27)+"...");
		} else {
			title.setText(celler.getCellarName());
		}
		
		if (celler.getNameCategory().length() > 15){
			titleCategory.setText(celler.getNameCategory().substring(0, 12) + "...");
		} else {
			titleCategory.setText(celler.getNameCategory());
		}
		
		txtDientich.setText(celler.getHect());
		try {
			txtSanluong.setText(doubleToStringNoDecimal(Double.parseDouble(celler.getAmpoller())));	
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		txtDes.setText(celler.getDesCriptionE());
		btnPhone.setText("+34 "+celler.getPhone());
		
		ImageLoader.getInstance().displayImage("http://enoguia.cat/img/logos/"+celler.getLogo(), imgLogo, options);
		ImageLoader.getInstance().displayImage("http://enoguia.cat/img/fotos/"+celler.getPhoto(), imgCover, options);
		
		txtAddress.setText(celler.getAddress());
		
		// options values;
		txtSchedule.setText(celler.getHorariE());
		txtPrice.setText(celler.getPriceE());
		txtLang.setText(celler.getLanguageE());
		txtCapicity.setText("Min: "+celler.getCapityMin()+ " Max: "+celler.getCapityMax());
		txtWine.setText(celler.getVinE());
		txtVisit.setText(celler.getVisitYes());
		
		txtListVins.setText(celler.getListtaVins());
		
		btnBack.setOnTouchListener(this);
		
		btnPhone.setOnTouchListener(this);
		btnWeb.setOnTouchListener(this);
		btnEmail.setOnTouchListener(this);
		btnFace.setOnTouchListener(this);
		btnTw.setOnTouchListener(this);
		
//		titleDirection.setOnTouchListener(this);
		
		llDirection.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				/*Log.i("DATA", "direction-----------");
				Intent t = new Intent(getActivity(), DirectionActivity.class);
				Log.i("DATA", "LAT: "+celler.getLat());
				t.putExtra("celler", celler);
				startActivity(t);*/
				Fragment productDetailFragment = DirectionFragment.newInstance();
				FragmentTransaction transaction = getFragmentManager().beginTransaction();
				transaction.addToBackStack(null);
				Bundle b = new Bundle();
				
				b.putParcelable("celler", celler);
				productDetailFragment.setArguments(b);
				transaction.replace(R.id.replace, productDetailFragment).commit();
				
				
				
			}
		});
		
		btnLike.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				/*if (liked == 0){
					db.insertLike(celler, 1);	
					liked = 1;
				} else if (liked == 1) {
					liked = 0;
					db.insertLike(celler, 0);
				} */
				
				if (liked == 0){
					db.insertIntoTableLike(celler, 1);
					liked = 1;
					btnLike.setImageResource(R.drawable.btn_like_selector_dis);
				} else if (liked == 1) {
					liked = 0;
					db.unlike(celler.getId());
					btnLike.setImageResource(R.drawable.btn_like_selector);
				} 
			}
		});
	}
	
	void initCA() {
		
		if (celler.getCellarName().length() > 30){
			title.setText(celler.getCellarName().substring(0, 27)+"...");
		} else {
			title.setText(celler.getCellarName());
		}
		
		if (celler.getNameCategory().length() > 15){
			titleCategory.setText(celler.getNameCategory().substring(0, 12) + "...");
		} else {
			titleCategory.setText(celler.getNameCategory());
		}
		
		txtDientich.setText(celler.getHect());
		txtSanluong.setText(doubleToStringNoDecimal(Double.parseDouble(celler.getAmpoller())));
		txtDes.setText(celler.getDesCriptionCA());
		btnPhone.setText("+34 "+celler.getPhone());
		
		ImageLoader.getInstance().displayImage("http://enoguia.cat/img/logos/"+celler.getLogo(), imgLogo, options);
		ImageLoader.getInstance().displayImage("http://enoguia.cat/img/fotos/"+celler.getPhoto(), imgCover, options);
		
		txtAddress.setText(celler.getAddress());
		
		// options values;
		txtSchedule.setText(celler.getHorariCA());
		txtPrice.setText(celler.getPriceCA());
		txtLang.setText(celler.getLanguageE());
		txtCapicity.setText("Min: "+celler.getCapityMin()+ " Max: "+celler.getCapityMax());
		txtWine.setText(celler.getVinCA());
		txtVisit.setText(celler.getVisitYes());
		
		txtListVins.setText(celler.getListtaVins());
		
		btnBack.setOnTouchListener(this);
		
		btnPhone.setOnTouchListener(this);
		btnWeb.setOnTouchListener(this);
		btnEmail.setOnTouchListener(this);
		btnFace.setOnTouchListener(this);
		btnTw.setOnTouchListener(this);
		
//		titleDirection.setOnTouchListener(this);
		
		llDirection.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				/*Log.i("DATA", "direction-----------");
				Intent t = new Intent(getActivity(), DirectionActivity.class);
				Log.i("DATA", "LAT: "+celler.getLat());
				t.putExtra("celler", celler);
				startActivity(t);*/
				Fragment productDetailFragment = DirectionFragment.newInstance();
				FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
				transaction.addToBackStack(null);
				Bundle b = new Bundle();
				
				b.putParcelable("celler", celler);
				productDetailFragment.setArguments(b);
				transaction.replace(R.id.replace, productDetailFragment).commit();
				
				
				
			}
		});
		
		btnLike.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				/*if (liked == 0){
					db.insertLike(celler, 1);	
					liked = 1;
				} else if (liked == 1) {
					liked = 0;
					db.insertLike(celler, 0);
				} */
				
				if (liked == 0){
					db.insertIntoTableLike(celler, 1);
					liked = 1;
					btnLike.setImageResource(R.drawable.btn_like_selector_dis);
				} else if (liked == 1) {
					liked = 0;
					db.unlike(celler.getId());
					btnLike.setImageResource(R.drawable.btn_like_selector);
				} 
			}
		});
	}

	void initES() {
	
	if (celler.getCellarName().length() > 30){
		title.setText(celler.getCellarName().substring(0, 27)+"...");
	} else {
		title.setText(celler.getCellarName());
	}
	
	if (celler.getNameCategory().length() > 15){
		titleCategory.setText(celler.getNameCategory().substring(0, 12) + "...");
	} else {
		titleCategory.setText(celler.getNameCategory());
	}
	
	txtDientich.setText(celler.getHect());
	txtSanluong.setText(doubleToStringNoDecimal(Double.parseDouble(celler.getAmpoller())));
	txtDes.setText(celler.getDesCriptionES());
	btnPhone.setText("+34 "+celler.getPhone());
	
	ImageLoader.getInstance().displayImage("http://enoguia.cat/img/logos/"+celler.getLogo(), imgLogo, options);
	ImageLoader.getInstance().displayImage("http://enoguia.cat/img/fotos/"+celler.getPhoto(), imgCover, options);
	
	txtAddress.setText(celler.getAddress());
	
	// options values;
	txtSchedule.setText(celler.getHorariES());
	txtPrice.setText(celler.getPriceES());
	txtLang.setText(celler.getLanguageE());
	txtCapicity.setText("Min: "+celler.getCapityMin()+ " Max: "+celler.getCapityMax());
	txtWine.setText(celler.getVinES());
	txtVisit.setText(celler.getVisitYes());
	
	txtListVins.setText(celler.getListtaVins());
	
	btnBack.setOnTouchListener(this);
	
	btnPhone.setOnTouchListener(this);
	btnWeb.setOnTouchListener(this);
	btnEmail.setOnTouchListener(this);
	btnFace.setOnTouchListener(this);
	btnTw.setOnTouchListener(this);
	
//	titleDirection.setOnTouchListener(this);
	
	llDirection.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			/*Log.i("DATA", "direction-----------");
			Intent t = new Intent(getActivity(), DirectionActivity.class);
			Log.i("DATA", "LAT: "+celler.getLat());
			t.putExtra("celler", celler);
			startActivity(t);*/
			Fragment productDetailFragment = DirectionFragment.newInstance();
			FragmentTransaction transaction = getFragmentManager().beginTransaction();
			transaction.addToBackStack(null);
			Bundle b = new Bundle();
			
			b.putParcelable("celler", celler);
			productDetailFragment.setArguments(b);
			transaction.replace(R.id.replace, productDetailFragment).commit();
			
			
			
		}
	});
	
	btnLike.setOnClickListener(new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			/*if (liked == 0){
				db.insertLike(celler, 1);	
				liked = 1;
			} else if (liked == 1) {
				liked = 0;
				db.insertLike(celler, 0);
			} */
			
			if (liked == 0){
				db.insertIntoTableLike(celler, 1);
				liked = 1;
				btnLike.setImageResource(R.drawable.btn_like_selector_dis);
			} else if (liked == 1) {
				liked = 0;
				db.unlike(celler.getId());
				btnLike.setImageResource(R.drawable.btn_like_selector);
			} 
		}
	});
}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.btn_back:
			if (event.getAction() == MotionEvent.ACTION_UP) {
				getActivity().onBackPressed();
			}
			break;
			
		case R.id.btn_phone:
			if (event.getAction() == MotionEvent.ACTION_UP) {
				callPhone();
			}
			break;
		case R.id.btn_web:
			if (event.getAction() == MotionEvent.ACTION_UP) {
				openWeb();
			}
			break;
		case R.id.btn_email:
			if (event.getAction() == MotionEvent.ACTION_UP) {
				composeEmail();
			}
			break;
		case R.id.ll_direction:
			if (event.getAction() == MotionEvent.ACTION_UP){
				
			}
			break;
		case R.id.btn_facebook:
			if (event.getAction() == MotionEvent.ACTION_UP){
				shareUrlFacebook();
//				postToFacebook();
//				postOnWall();
			}
			break;
		case R.id.btn_tw:
			if (event.getAction() == MotionEvent.ACTION_UP){
				/*Intent i = new Intent(Intent.ACTION_SEND);
				i.setType("text/plain");
				i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
				i.putExtra(Intent.EXTRA_TEXT, "http://"+celler.getWeb());
				startActivity(Intent.createChooser(i, "Share URL"));*/
				onClickTwitt();
			}
			break;
		default:
			break;
		}
		
		return false;
	}
	 
	
	
	
	void callPhone(){
		
		dC = new Dialog(getActivity());
		dC.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dC.setContentView(R.layout.dialog_confirm_call_phone);
		
		
		TextView txtThoat = (TextView) dC.findViewById(R.id.str_canhbao_thoat);
		
		Button btnCancel = (Button) dC.findViewById(R.id.btn_cancel);
		Button btnCall = (Button) dC.findViewById(R.id.btn_call);
		dC.show();
		dC.getWindow().setBackgroundDrawable(new ColorDrawable(0));
		dC.setCanceledOnTouchOutside(true);
		dC.getWindow().setGravity(Gravity.CENTER);
		dC.show();
		
		// setonclick
		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dC.dismiss();
			}
		});
		btnCall.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dC.dismiss();
				call();
			}
		});
		
	}
	
	public void call() {   
        Intent callIntent = new Intent(Intent.ACTION_CALL);          
        callIntent.setData(Uri.parse("tel:"+celler.getPhone()));          
        startActivity(callIntent);  
	}
	
	void openWeb(){
		dW = new Dialog(getActivity());
		dW.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dW.setContentView(R.layout.dialog_confirm_open_web);
		
		
		TextView txtThoat = (TextView) dW.findViewById(R.id.str_canhbao_thoat);
		
		Button btnCancel = (Button) dW.findViewById(R.id.btn_cancel);
		Button btnCall = (Button) dW.findViewById(R.id.btn_call);
		dW.show();
		dW.getWindow().setBackgroundDrawable(new ColorDrawable(0));
		dW.setCanceledOnTouchOutside(true);
		dW.getWindow().setGravity(Gravity.CENTER);
		dW.show();
		
		// setonclick
		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dW.dismiss();
			}
		});
		btnCall.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dW.dismiss();
				web();
			}
		});
	}
	
	public void web(){
		Uri uriUrl = Uri.parse("http://"+celler.getWeb()); 
		Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);  
		startActivity(launchBrowser);
	}
	
	void composeEmail(){
		dM = new Dialog(getActivity());
		dM.requestWindowFeature(Window.FEATURE_NO_TITLE);
		dM.setContentView(R.layout.dialog_confirm_compose_email);
		
		
		TextView txtThoat = (TextView) dM.findViewById(R.id.str_canhbao_thoat);
		
		Button btnCancel = (Button) dM.findViewById(R.id.btn_cancel);
		Button btnCall = (Button) dM.findViewById(R.id.btn_call);
		dM.show();
		dM.getWindow().setBackgroundDrawable(new ColorDrawable(0));
		dM.setCanceledOnTouchOutside(true);
		dM.getWindow().setGravity(Gravity.CENTER);
		dM.show();
		
		// setonclick
		btnCancel.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dM.dismiss();
			}
		});
		btnCall.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dM.dismiss();
				email();
			}
		});
	}
	
	public void email(){
		Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"+celler.getEmail()));
		emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");
		startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
	}
	
	// share link to fb
		public void shareUrlFacebook() {
			/*
			 * Facebook - "com.facebook.katana" Twitter - "com.twitter.android"
			 * Instagram - "com.instagram.android" Pinterest - "com.pinterest"
			 */
			// getPackageName() from Context or Activity object
			final String appPackageName = "com.facebook.katana";
			Intent intent = getActivity().getPackageManager().getLaunchIntentForPackage(
					"com.facebook.katana");
			
			
			if (intent != null) {
				Intent share = new Intent(android.content.Intent.ACTION_SEND);
				share.setType("text/plain");
				share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
				// add data
				share.putExtra(Intent.EXTRA_TEXT, "http://"+celler.getWeb());
				startActivity(Intent.createChooser(share, "Enoguia"));

			} else {

				try {
					startActivity(new Intent(Intent.ACTION_VIEW,
							Uri.parse("market://details?id=" + appPackageName)));
				} catch (android.content.ActivityNotFoundException anfe) {
					startActivity(new Intent(
							Intent.ACTION_VIEW,
							Uri.parse("http://play.google.com/store/apps/details?id="
									+ appPackageName)));
				}
			}
		}
		
	public String doubleToStringNoDecimal(double d) {
		// dau phẩy
		/*DecimalFormat formatter = (DecimalFormat) NumberFormat
				.getInstance(Locale.UK);
		;
		formatter.applyPattern("#,###");*/
		
		// dau cham
		DecimalFormat df = new DecimalFormat(
			      "#,##0", 
			      new DecimalFormatSymbols(new Locale("pt", "BR")));
		return df.format(d);
	}

	public void onClickTwitt() {
		if (isNetworkAvailable()) {
			Twitt_Sharing twitt = new Twitt_Sharing(getActivity(),
					consumer_key, secret_key);
			string_img_url = "http://www.bharatbpo.in/bbpo/images/AndroidLogo.jpg";
			string_msg = "http://chintankhetiya.wordpress.com/";
			// here we have web url image so we have to make it as file to
			// upload
			// String_to_File(string_img_url);
			twitt.shareToTwitter(string_msg, casted_image);
		} else {

		}
	}
			
	public boolean isNetworkAvailable() {
		ConnectivityManager connectivityManager = (ConnectivityManager) getActivity()
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connectivityManager == null) {
			return false;
		} else {
			NetworkInfo[] info = connectivityManager.getAllNetworkInfo();
			if (info != null) {
				for (int i = 0; i < info.length; i++) {
					if (info[i].getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
				}
			}
		}
		return false;
	}

	private void showToast(String msg) {
		Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG).show();
	}

	@SuppressWarnings("deprecation")
	void postToFacebook() {
		OnLoginListener onLoginListener = new OnLoginListener() {
		    @Override
		    public void onLogin() {
		        // change the state of the button or do whatever you want
		        Log.i("DATA", "Logged in");
		        postOnWall();
		    }

		    @Override
		    public void onNotAcceptingPermissions(Permission.Type type) {
		        // user didn't accept READ or WRITE permission
		        Log.w("DATA", String.format("You didn't accept %s permissions", type.name()));
		    }

			@Override
			public void onThinking() {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onException(Throwable arg0) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onFail(String arg0) {
				// TODO Auto-generated method stub
				
			}

		    /* 
		     * You can override other methods here: 
		     * onThinking(), onFail(String reason), onException(Throwable throwable)
		     */ 
		};
		
		mSimpleFacebook.login(onLoginListener);
	}
		    
	public void postOnWall() {
		OnPublishListener onPublishListener = new OnPublishListener() {
		    @Override
		    public void onComplete(String postId) {
		        Log.i("DATA", "Published successfully. The new post id = " + postId);
		    }

		};
		
		Feed feed = new Feed.Builder()
	    .setMessage("Share my timeline")
	    .setName("Share...")
	    .setCaption(celler.getCellarName())
	    .setDescription(celler.getDesCriptionE())
	    .setPicture(celler.getPhoto())
	    .setLink(celler.getWeb())
	    .build();
		
		mSimpleFacebook.publish(feed, true, onPublishListener);

		
		
	}
	
	
}
